flag = 0
while flag == 0:
    num = int(input())
    if num != 0:
        dp = [1, 2, 4]
        i = 4
        if num <= 2:
            print(num)
            continue
        if num == 3:
            print(4)
            continue
        if num == 4:
            print(7)
            continue
        else:
            f = 1
            s = 2
            t = 4
            res = 7
            while i < num:
                f = s
                s = t
                t = res
                res = f + s + t
                # dp.append(dp[i - 1] + dp[i - 2] + dp[i - 3])
                i += 1
            print(res)
    else:
        flag = 1